10 / 17

What does the pattern attribute do?

Using the pattern Attribute in HTML

The pattern attribute in HTML allows you to define a regular expression that the input value must match before the form can be submitted. It’s commonly used for custom validation rules beyond what built-in input types provide.

Key Points About pattern
  1. 1

    Works with text-based inputs like text, email, password, and search.

  2. 2

    The value must match the regex pattern for the form to submit successfully.

  3. 3

    If the value doesn’t match, the browser prevents submission and shows an error message.

  4. 4

    The title attribute can be used alongside pattern to provide a helpful hint about the required format.

Example of pattern Usage